package com.kdzy.lshy.socity_server.controller;

import com.kdzy.lshy.socity_server.service.SocityQuickService;
import com.kdzy.lshy.socity_server.service.WechartService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 社区直通车控制器
 * @author cly
 * @since 2018-07-23
 */
@RestController
@RequestMapping("/socityQuick")
@CrossOrigin("*")
@Api(value = "SocityQuickController", description = "社区直通车相关")
public class SocityQuickController {

    private static final Logger logger = LoggerFactory.getLogger(SocityQuickController.class);

    @Autowired
    private SocityQuickService socityQuickService;

    /**
     * 补充居住证
     * @param param 包含居住证照片路径等信息
     * @return 结果集 - 补充是否成功
     */
    @RequestMapping(value = "/doResidentPermits", method = RequestMethod.POST)
    @ApiOperation(notes = "/doResidentPermits", httpMethod = "POST", value = "社区直通车 - 补充居住证", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 0, message = "更新居住证成功"),
            @ApiResponse(code = 1, message = "记录不存在"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常")
    })
    public Object doResidentPermits(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"quickId\": \"唯一标识\",\n" +
                            " \"res_id\": \"证件ID\",\n" +
                            " \"res_num\": 证件份数,\n" +
                            " \"res_type\": 证件类型  0照片 1excel 2pdf 3doc 4zip 5其他,\n" +
                            " \"res_url\": \"证件存储地址\",\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产\n" +
                            "}")
            String param, HttpServletRequest request){
        logger.info("进入《社区直通车 - 补充居住证）》doResidentPermits()方法；入参param = " + param);
        return socityQuickService.doResidentPermits(param, request);
    }

    /**
     * 查询居住证 - 居民
     * @param param 包含居民id，业务id等等
     * @return 结果集 - 居住证信息
     */
    @RequestMapping(value = "/dwellerResidentPermitsList", method = RequestMethod.POST)
    @ApiOperation(notes = "/dwellerResidentPermitsList", httpMethod = "POST", value = "社区直通车 - 查询居住证 - 居民", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 0, message = "成功"),
            @ApiResponse(code = 1, message = "结果集为空"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 33, message = "systoken过期"),
            @ApiResponse(code = 331, message = "systoken不一致"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常")
    })
    public Object dwellerResidentPermitsList(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"dweller_id\": \"居民ID\",\n" +
                            " \"bizz_id\": \"业务ID\",\n" +
                            " \"res_id\": \"证件资料ID\",\n" +
                            " \"systoken\": \"(当visit_plat = 0 时)全局token\",\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产\n" +
                            "}")
                    String param, HttpServletRequest request){
        logger.info("进入《社区直通车 - 查询居住证 - 居民》dwellerResidentPermitsList()方法；入参param = " + param);
        return socityQuickService.dwellerResidentPermitsList(param, request);
    }

    /**
     * 更新居住证办理状态 - 工作人员
     * @param param 包含记录主键
     * @return 结果集 - 成功/失败
     */
    @RequestMapping(value = "/updateResidentPermitsType", method = RequestMethod.POST)
    @ApiOperation(notes = "/updateResidentPermitsType", httpMethod = "POST", value = "社区直通车 - 更新居住证办理状态 - 工作人员", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 0, message = "状态更新成功"),
            @ApiResponse(code = 1, message = "结果集为空"),
            @ApiResponse(code = 12, message = "数据有误"),
            @ApiResponse(code = 13, message = "重复插入"),
            @ApiResponse(code = 11, message = "状态码更新不对"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常")
    })
    public Object updateResidentPermitsType(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"socityId\": \"社区ID\",\n" +
                            " \"quickId\": \"记录唯一标识\",\n" +
                            " \"res_note\": \"当res_type = 8时\",\n" +
                            " \"res_type\": 处理结果：1提交材料 2资料有误 3资料正确 4发送上门短信通知 5上门审核后失败（不在家） 6上门审核后成功 7已发放 8上门审核后失败（在家）,\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产\n" +
                            "}")
            String param, HttpServletRequest request){
        logger.info("进入《社区直通车 - 更新居住证办理状态 - 工作人员》updateResidentPermitsType()方法；入参param = " + param);
        return socityQuickService.updateResidentPermitsType(param, request);
    }

}
